package cn.edu.scau.cmi.xiaozhenlin.FactoryMethod;

import cn.edu.scau.cmi.xiaozhenlin.insurance.Insurance;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;

public class FactoryController {

	@FXML
	private ImageView img;

	@FXML
	private ChoiceBox<String> sp_what;

	@FXML
	private TextArea tv_showMsg;

	public void Init() {
		// TODO Auto-generated method stub
		ObservableList<String> options = FXCollections.observableArrayList("身体受伤", "汽车损坏", "汽车刮伤");
		System.out.println(options);
		this.sp_what.setItems(options);
		// this.sp_what.getSelectionModel().select(0);
		sp_what.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
			@Override
			public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
				// TODO 自动生成的方法存根
				sp_what.getSelectionModel().select(arg2.intValue());
				String select = sp_what.getValue();
				InsuranceFactory factory = null;
				switch (select) {
				case "身体受伤": {
					factory = new PhysicalInjuryFactory();
					break;
				}
				case "汽车损坏": {
					factory = new CarDamamgeFactory();
					break;
				}
				case "汽车刮伤": {
					factory = new ScratchFactory();
					break;
				}
				default:
					break;
				}
				tv_showMsg.clear();
				System.out.println(sp_what.getValue());
				if (factory != null) {
					Insurance insurance = factory.getInstance();
					tv_showMsg.setText(insurance.claim());
				}

			}

		});
	}

}
